﻿using DirectoryServicesProtocolsExtensions.MetaData;
using DirectoryServicesProtocolsExtensions.MetaData.SemanticAttributeGroupings;

namespace DirectoryServicesProtocolsExtensions.LdapConnection.Validation
{
    using System.DirectoryServices.Protocols;
    using MetaData;

    public static class ConnectivityValidator
    {
        public static void TestConnectivity(this LdapConnection ldapConnection)
        {
            IsHostOrDomainBindable(ldapConnection);
            ldapConnection.GetSubschemaSubentryDN();

            ldapConnection.GetAttributeMetaData(
                "cn",
                new LdapMetaMapFactory(
                    new LdapMetaMapFactoryInitializationValues(
                        new GuidEncodedAttributeGroup(),
                        new SidEncodedAttributeGroup(),
                        new Int64DateTimeEncodedAttributeGroup(),
                        new StringEncodedIntAttributeGroup(),
                        new AttributesWhichMayRequireExpansionGroup()
                    )));
        }

        public static void IsHostOrDomainBindable(
            this LdapConnection ldapConnection)
        {
            ldapConnection.Bind();
        }
    }
}
